package com.shijunhao.graduation.listener;

import com.shijunhao.graduation.event.OperationLogEvent;
import com.shijunhao.graduation.service.business.ISystemOperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author: shijunhao
 * @date: 2022/3/15 23:30
 * @description: 操作日志监听器
 */
@Component
public class OperationEventListener {

    private final ISystemOperationLogService systemOperationLogService;

    @Autowired
    public OperationEventListener(ISystemOperationLogService systemOperationLogService) {
        this.systemOperationLogService = systemOperationLogService;
    }

    @Async
    @Order
    @EventListener
    public void onApplicationEvent(OperationLogEvent event) {
        systemOperationLogService.insertOne(event.getSource());
    }
}
